/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanImage.java
 *
 * Created on 08/06/2011, 11:08:12
 */
package chromaticitymoments;

import java.awt.Graphics;
import java.awt.Image;

/**
 *
 * @author frank.aguilar
 */
public class PanImage extends javax.swing.JPanel {
    private Image image;
    private String name;

    
    /** Creates new form PanImage */
    public PanImage() {
        initComponents();
        name=null;
        image=null;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(chromaticitymoments.ChromaticityMomentsApp.class).getContext().getResourceMap(PanImage.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 280, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 227, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    public Image getImage() {
        return image;
    }

    public void setImage(Image image,String name) {
        this.image = image;
        this.name=name;
    }
    
    public void paint(Graphics g){
        super.paint(g);

        if(image!=null){
            int y=(this.getHeight()-image.getHeight(null))/2;
            int x=(this.getWidth()-image.getWidth(null))/2;
            g.drawImage(image, x, y, null);
        }
        if(name!=null){
            g.drawString(name,10,20);
        }
    }

    public String getImageName(){
        return this.name;
    }
    

}
